package pteam;
import simulator.Actor;
import simulator.BeaconSensor;
import simulator.Robot;
import simulator.Sensor;
import simulator.BumpSensor;

public class DumbGold implements Actor {
  private boolean touched = false;
  private boolean inred = false;
  private boolean ingreen = false;
  //private boolean inboth = false;
  
  private static final int BEACONSEEK = 5;
  private static final int BACKUP = 5;
  private static final int ANGLE = 30;
  private static final int FWDWAIT = 1;

  public DumbGold() { }
  
  public String getMaze() {
    return "Gold";
  }
  
  public void act(Robot r) {
    if(inred || ingreen) {
      if(inred) {
        r.turnLeft();
        r.waitAngle(BEACONSEEK);
      }else{
        r.turnRight();
        r.waitAngle(BEACONSEEK);
      }
    }else{
      if(touched) {
        r.goBackward();
        r.waitDistance(BACKUP);
        if((int)(Math.random() * 2) == 0)
          r.turnLeft();
        else
          r.turnRight();
        r.waitAngle(ANGLE);
      }
    }
    r.goForward();
    r.waitDistance(FWDWAIT);
  }
  
  public void updateSensors(Sensor[] sensors) {
    touched = sensors[0].getState()[0] == BumpSensor.PRESSED;
    inred = false;//((BeaconSensor)sensors[5]).INRED == 1.;
    ingreen = false;// ((BeaconSensor)sensors[5]).INGREEN == 1.;
    //inboth = ((BeaconSensor)sensors[5]).INBOTH == 2.;
  }
  
}